package com.longrise.android.byjk.plugins.vip.integralexchange;

import android.view.View;
import android.widget.TextView;
import com.longrise.android.byjk.R;
import com.longrise.common.base.BaseActivity;
import com.longrise.android.byjk.utils.DialogUtil;

/**
 * Created by callxkj on 2017/5/4.
 * 关于积分兑换方面的弹窗
 */

public class IntegralExchangeDialogHelper {


    /**
     * 弹出积分兑换的弹窗
     * @param activity activity
     * @param goodsid 商品id
     * @param goodstype 商品类型
     * @param needscores 需要积分
     * @param listener 监听
     */
    public static void toShowIntegralExchangeDialog(final BaseActivity activity, final String goodsid,
                                                    final String goodstype, String needscores,
                                                    final ToIntegralExchangeListener listener) {
        View view = View.inflate(activity, R.layout.dialog_integralexchange, null);
        TextView tv_cancel = (TextView) view.findViewById(R.id.dialog_integralexchange_cancle);
        TextView tv_confirm = (TextView) view.findViewById(R.id.dialog_integralexchange_confirm);
        TextView tv_msg = (TextView) view.findViewById(R.id.dialog_integralexchange_tips);
        tv_cancel.setText("取消");
        tv_confirm.setText("确认");
        tv_msg.setText("兑换该皮肤需要消耗" + needscores + "积分");
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.getInstance().dismiss();
            }
        });
        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.getInstance().dismiss();
                if (listener != null) {
                  listener.toIntegralExchange(goodsid, goodstype);
                }
            }
        });
        DialogUtil.getInstance().creatAlertDialog(activity, view, 266, 171);
    }

    /**
     * 积分不足
     */
    public static void showIntegralnotenoughtDialog(final BaseActivity activity) {
        View view = View.inflate(activity, R.layout.dialog_integralexchange, null);
        TextView tv_cancel = (TextView) view.findViewById(R.id.dialog_integralexchange_cancle);
        TextView tv_confirm = (TextView) view.findViewById(R.id.dialog_integralexchange_confirm);
        TextView tv_msg = (TextView) view.findViewById(R.id.dialog_integralexchange_tips);
        tv_cancel.setText("取消");
        tv_confirm.setText("去赚积分");
        tv_msg.setText("您当前积分不足\n赶紧去赚取积分吧");
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.getInstance().dismiss();
            }
        });
        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.getInstance().dismiss();
                IntegralTaskUtil.toIntegralTask(activity);
            }
        });
        DialogUtil.getInstance().creatAlertDialog(activity, view, 266, 171);
    }


    /**
     * 弹出积分兑换勋章的弹窗
     * @param activity activity
     * @param goodsid 商品id
     * @param goodstype 商品类型
     * @param needscores 需要积分
     * @param listener 监听
     */
    public static void toShowIntegralExchangexzDialog(final BaseActivity activity, final String goodsid,
                                                    final String goodstype, String needscores,
                                                    final ToIntegralExchangeListener listener) {
        View view = View.inflate(activity, R.layout.dialog_integralexchange, null);
        TextView tv_cancel = (TextView) view.findViewById(R.id.dialog_integralexchange_cancle);
        TextView tv_confirm = (TextView) view.findViewById(R.id.dialog_integralexchange_confirm);
        TextView tv_msg = (TextView) view.findViewById(R.id.dialog_integralexchange_tips);
        tv_cancel.setText("取消");
        tv_confirm.setText("确认");
        tv_msg.setText("兑换该勋章需要消耗" + needscores + "积分");
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.getInstance().dismiss();
            }
        });
        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.getInstance().dismiss();
                if (listener != null) {
                    listener.toIntegralExchange(goodsid, goodstype);
                }
            }
        });
        DialogUtil.getInstance().creatAlertDialog(activity, view, 266, 171);
    }


    interface ToIntegralExchangeListener {
        void toIntegralExchange(String goodsid, String goodstype);
    }
}
